Skip to main content

Viewer Object Utils

The ViewerObjectUtils class, part of the @promaton/scan-viewer package, provides a collection of utility functions to simplify working with ViewerObjects. This article outlines its constructors, methods, and their respective use cases.

Constructor

new ViewerObjectUtils()

Creates a new instance of the ViewerObjectUtils class.

Returns:

  • ViewerObjectUtils

Methods

fileSupportsVertexColors()

Call Signature 1:

static fileSupportsVertexColors(viewerObject: ViewerObject): boolean

Checks if the viewerObject has a file type that supports a color attribute.

Parameters:

  • viewerObject: ViewerObject

Returns:

  • boolean

Call Signature 2:

static fileSupportsVertexColors(filetype?: string): boolean

Checks if the filetype supports a color attribute.

Parameters:

  • filetype?: string

Returns:

  • boolean

getById()

static getById(id: string): undefined | ViewerObject

Retrieves a ViewerObject by its ID from the useObjects store.

Parameters:

  • id: string

Returns:

  • undefined | ViewerObject

getFileType()

static getFileType(viewerObject?: ViewerObject): undefined | string

Determines or infers the file type for a ViewerObject.

Parameters:

  • viewerObject?: ViewerObject

Returns:

  • undefined | string

getGeometryForViewerObject()

static getGeometryForViewerObject(viewerObject: ViewerObject, requireBvh: boolean = true): Promise<BufferGeometry<NormalBufferAttributes>>

Retrieves the THREE.BufferGeometry for a mesh ViewerObject. If not loaded, it preloads and caches the geometry.

Parameters:

  • viewerObject: ViewerObject
  • requireBvh: boolean (default: true)

Returns:

  • Promise<BufferGeometry<NormalBufferAttributes>>

getImageLoader()

static getImageLoader(fileType?: string): typeof DicomLoader | typeof XrayLoader

Retrieves the Three.js loader for supported CBCT image formats and containers.

Parameters:

  • fileType?: string

Returns:

  • typeof DicomLoader | typeof XrayLoader

getLoader()

static getLoader(input?: FileTypeOrObject): undefined | typeof CmfLoader | typeof DicomLoader | typeof DRACOLoader | typeof JsonLoader | typeof OBJLoader | typeof PsgLoader | typeof XrayLoader

Gets the configured loader for a given file type or ViewerObject.

Parameters:

  • input?: FileTypeOrObject

Returns:

  • undefined | typeof CmfLoader | typeof DicomLoader | typeof DRACOLoader | typeof JsonLoader | typeof OBJLoader | typeof PsgLoader | typeof XrayLoader

getMeshLoader()

static getMeshLoader(fileType: string): typeof CmfLoader | typeof DRACOLoader | typeof OBJLoader

Retrieves the Three.js loader for a specified mesh file type.

Parameters:

  • fileType: string

Returns:

  • typeof CmfLoader | typeof DRACOLoader | typeof OBJLoader

getWorldMatrixForViewerObject()

static getWorldMatrixForViewerObject(viewerObject: ViewerObject): Matrix4

Gets the world matrix in the current coordinate system for a ViewerObject, even if it is not visible or present in the scene graph.

Parameters:

  • viewerObject: ViewerObject

Returns:

  • Matrix4

inferTypeFromUrl()

static inferTypeFromUrl(url: string | string[]): undefined | FileType

Infers the file type based on the file extension in the URL.

Parameters:

  • url: string | string[]

Returns:

  • undefined | FileType

isImageFile()

Call Signature 1:

static isImageFile(viewerObject: ViewerObject): boolean

Checks if the viewerObject contains a supported type of image data.

Parameters:

  • viewerObject: ViewerObject

Returns:

  • boolean

Call Signature 2:

static isImageFile(filetype?: string): boolean

Checks if the filetype corresponds to a supported image format.

Parameters:

  • filetype?: string

Returns:

  • boolean

isMeshFile()

Call Signature 1:

static isMeshFile(viewerObject: ViewerObject): boolean

Checks if the viewerObject contains a supported type of mesh data.

Parameters:

  • viewerObject: ViewerObject

Returns:

  • boolean

Call Signature 2:

static isMeshFile(filetype?: string): boolean

Checks if the filetype corresponds to a supported mesh format.

Parameters:

  • filetype?: string

Returns:

  • boolean

preloadViewerObject()

static preloadViewerObject(viewerObject: ViewerObject, onProgress?: (e: any, url?: string) => void): Promise<BufferGeometry<NormalBufferAttributes>>

Preloads ViewerObject data into the cache before adding it to the scene.

Parameters:

  • viewerObject: ViewerObject
  • onProgress?: (e: any, url?: string) => void

Returns:

  • Promise<BufferGeometry<NormalBufferAttributes>>

The ViewerObjectUtils class is a powerful tool for managing and interacting with ViewerObjects. Its methods provide flexibility and efficiency for handling various file types, geometries, and loaders in 3D applications.